package com.gemptc.wode.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import com.gemptc.bean.PostInfoBean;
import com.gemptc.daoimp.SelectImp;
import com.gemptc.wode.daoImp.Select_WouserImp;
import com.jixiantubu.entity.Post_InfoDaoimp;

/**
 * Servlet implementation class Wo_Post_servlet
 */
@WebServlet("/Wo_Post_servlet")
public class Wo_Post_servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Wo_Post_servlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		PrintWriter printWriter = response.getWriter();
		String value = request.getParameter("key");
		System.out.println(value);
		Select_WouserImp wouser = new Select_WouserImp();
		switch (Integer.parseInt(value)) {
		case 1:
			List<PostInfoBean> pList = new ArrayList<PostInfoBean>();
			Post_InfoDaoimp p1 = new Post_InfoDaoimp();
			String username = request.getParameter("username");
			int userid = wouser.selectuserid(username);
			pList = p1.selectpost(userid);
			JSONArray jsonArray = JSONArray.fromObject(pList);
			String result = jsonArray.toString();
			printWriter.write(result);
			System.out.println(result);
			printWriter.close();
			break;
		case 2:
			List<PostInfoBean> pbList = new ArrayList<PostInfoBean>();
			SelectImp sp = new SelectImp();
			String reply_user_id = request.getParameter("reply_user_id");
			System.out.println(reply_user_id);
			pbList = sp.selectreply(Integer.parseInt(reply_user_id));

			System.out.println("pbList------" + pbList);
			JSONArray jsonArray1 = JSONArray.fromObject(pbList);
			String result1 = jsonArray1.toString();
			printWriter.write(result1);
			// printWriter.write(jsonArray1.toString());
			System.out.println("1234============" + result1);
			printWriter.close();
			break;
		case 3:
			List<PostInfoBean> lp = new ArrayList<PostInfoBean>();
			Post_InfoDaoimp pi = new Post_InfoDaoimp();
			username = request.getParameter("username");
			userid = wouser.selectuserid(username);
			lp = pi.selectcollectpost(userid);
			JSONArray ja = JSONArray.fromObject(lp);
			String res = ja.toString();
			printWriter.write(res);
			System.out.println("1*******============" + res);
			printWriter.close();

			break;

		default:
			break;
		}

	}

}
